package http;

import com.alibaba.fastjson.JSON;
import model.character.RestUserAddress;
import model.dictionary.RestPhoto;
import model.order.RestOrderCar;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2016/3/9.
 */
public class paramPostTets {
    public  static void main(String[] args){
        paramPost();
    }

    private static void paramPost(){

        try {

//            List<RestOrderCar> orderCars = new ArrayList<RestOrderCar>();
//
//            RestOrderCar restOrderCar = new RestOrderCar();
//            restOrderCar.setLicense("1231231");
//            restOrderCar.setPriority(1);
//            restOrderCar.setVinCode("2324432");
//            restOrderCar.setRemark("sdfasdfa大师傅的");
//            restOrderCar.setCreateDate(new Date());
//
//            RestOrderCar restOrderCar7 = new RestOrderCar();
//            restOrderCar7.setLicense("1231231");
//            restOrderCar7.setPriority(7);
//            restOrderCar7.setVinCode("2324432");
//            restOrderCar7.setRemark("sdfasdfa大师傅的");
//            restOrderCar7.setCreateDate(new Date());
//
//
//            RestOrderCar restOrderCar2 = new RestOrderCar();
//            restOrderCar2.setLicense("1231231");
//            restOrderCar2.setPriority(2);
//            restOrderCar2.setVinCode("2324432");
//            restOrderCar2.setRemark("sdfasdfa大师傅的");
//            restOrderCar2.setCreateDate(new Date());
//
//
//            RestOrderCar restOrderCar3 = new RestOrderCar();
//            restOrderCar3.setLicense("1231231");
//            restOrderCar3.setPriority(3);
//            restOrderCar3.setVinCode("2324432");
//            restOrderCar3.setRemark("sdfasdfa大师傅的");
//            restOrderCar3.setCreateDate(new Date());
//
//
//            RestOrderCar restOrderCar4 = new RestOrderCar();
//            restOrderCar4.setLicense("1231231");
//            restOrderCar4.setPriority(4);
//            restOrderCar4.setVinCode("2324432");
//            restOrderCar4.setRemark("sdfasdfa大师傅的");
//            restOrderCar4.setCreateDate(new Date());
//
//            RestOrderCar restOrderCar5 = new RestOrderCar();
//            restOrderCar5.setLicense("1231231");
//            restOrderCar5.setPriority(5);
//            restOrderCar5.setVinCode("2324432");
//            restOrderCar5.setRemark("sdfasdfa大师傅的");
//            restOrderCar5.setCreateDate(new Date());
//
//
//            RestOrderCar restOrderCar6 = new RestOrderCar();
//            restOrderCar6.setLicense("1231231");
//            restOrderCar6.setPriority(6);
//            restOrderCar6.setVinCode("2324432");
//            restOrderCar6.setRemark("sdfasdfa大师傅的");
//            restOrderCar6.setCreateDate(new Date());
//
//            RestPhoto restPhoto = new RestPhoto();
//            restPhoto.setCreateDate(new Date());
//            restPhoto.setRemoteId("231321");
//            restPhoto.setType("img");
//
//            restOrderCar.setPhoto(restPhoto);
//
//            orderCars.add(restOrderCar);
//            orderCars.add(restOrderCar2);
//            orderCars.add(restOrderCar3);
//            orderCars.add(restOrderCar4);
//            orderCars.add(restOrderCar5);
//            orderCars.add(restOrderCar6);
//            orderCars.add(restOrderCar7);

            HttpClient httpclient = new HttpClient();
//            PostMethod httpPost =new PostMethod("http://139.196.240.232:8999/api/rest/ios/test/list");
            PostMethod httpPost =new PostMethod("http://localhost:8999/api/rest/worker/manager/post/company/13636572175");
            NameValuePair[] param = { new NameValuePair("lat", "31.2011"),
                    new NameValuePair("lgt", "121.634"),new NameValuePair("address", "sadgvcad"),
                    new NameValuePair("name", "GG_baihe"),new NameValuePair("mobiles", "162748392,123123,435124")};
            httpPost.setRequestBody(param);

//            RestUserAddress restUserAddress = new RestUserAddress();
//            restUserAddress.setAddress("sdfadf");
//            restUserAddress.setLat(Float.valueOf("12"));
//            restUserAddress.setLgt(Float.valueOf("12"));
//            restUserAddress.setAddressName("ssfa");
//            restUserAddress.setAddressMobile("sdfsdfs");
//
//            httpPost.setParameter("useraddress", JSON.toJSONString(restUserAddress));

            httpclient.executeMethod(httpPost);

            //打印服务器返回的状态
            System.out.println(httpPost.getStatusLine());
            //打印返回的信息
            InputStream stream = httpPost.getResponseBodyAsStream();

            BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
            StringBuffer buf = new StringBuffer();
            String line;
            while (null != (line = br.readLine())) {
                buf.append(line).append("\n");
            }
            System.out.println(buf.toString());
            //释放连接
            httpPost.releaseConnection();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
